import {setStore, getStore, removeStore} from '@/util/store'
import {validateNull} from '@/util/validate'
import {getDic} from '@/api/admin'
import {baseUrl} from '@/config/env';
import website from '@/const/website'

const common = {
  state: {
    isCollapse: false,
    isFullScreen: false,
    theme: getStore({
      name: 'theme'
    }) || '#409EFF',
    website: website,
  },
  actions: {
    // 获取字典公用类
    GetDic({
             commit,
             state,
             dispatch
           }, dic) {
      return new Promise((resolve, reject) => {
        if (dic instanceof Array) {
          Promise.all(dic.map(ele => getDic(ele))).then(data => {
            const result = {}
            dic.forEach((ele, index) => {
              result[ele] = data[index].data
            })
            resolve(result)
          })
        }
      })
    }
  },
  mutations: {
    SET_COLLAPSE: (state, action) => {
      state.isCollapse = !state.isCollapse
    },
    SET_FULLSCREEN: (state, action) => {
      state.isFullScren = !state.isFullScren
    },
    SET_THEME: (state, color) => {
      state.theme = color
      setStore({
        name: 'theme',
        content: state.theme
      })
    }
  }
}
export default common
